package com.ym.controller.medical;

import com.github.pagehelper.PageInfo;
import com.ym.common.constant.ValidRule;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.medical.domain.param.ServiceTermsQueryParam;
import com.ym.medical.domain.param.ServiceTermsUpdateParam;
import com.ym.medical.domain.vo.ServiceTermsListPcVO;
import com.ym.medical.service.IServiceTermsSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 服务条款管理
 */
@Api(tags = "服务条款管理")
@RestController
@RequestMapping("/management/ServiceTermsEntity")
public class ServiceTermsManagement extends BaseController {

    @Autowired
    private IServiceTermsSV serviceTermsSV;

    @ApiOperation("服务条款新增")
    @PostMapping("/add")
    public APIResponse insertServiceTermsEntity(
            @ApiParam(name = "ServiceTermsEntity", value = "服务条款实体", required = true)
            @Validated(value = {ValidRule.Add.class}) @RequestBody ServiceTermsUpdateParam updateParam) {
        Long id = serviceTermsSV.insertServiceTerms(updateParam);
        return successData(id);
    }

    @ApiOperation("服务条款修改")
    @PostMapping("/update")
    public APIResponse updateServiceTermsEntity(
            @ApiParam(name = "ServiceTermsEntity", value = "服务条款实体", required = true)
            @Validated(value = {ValidRule.Add.class}) @RequestBody ServiceTermsUpdateParam updateParam) {
        int result = serviceTermsSV.updateServiceTerms(updateParam);
        return successData(result);
    }

    @ApiOperation("服务条款删除")
    @PostMapping("/delete")
    public APIResponse deleteServiceTermsEntity(
            @ApiParam(name = "ids", value = "服务条款id", required = true) @RequestBody Long[] ids) {
        serviceTermsSV.deleteByIds(ids);
        return successMsg("服务条款删除成功");
    }

    @ApiOperation("服务条款展示")
    @GetMapping("/list")
    public APIResponse<PageInfo<ServiceTermsListPcVO>> listServiceTermsEntity(
            @ApiParam(name = "ServiceTermsEntity", value = "服务条款实体", required = true)
                    ServiceTermsQueryParam queryParam) {
        PageDomain.startPage();
        List<ServiceTermsListPcVO> serviceTermsListPcVOS = serviceTermsSV.selectListPC(queryParam);
        return successPage(serviceTermsListPcVOS);
    }
}
